'''
函数--作用域
'''

numa = 100


def fun():
    # 局部变量
    numb = 20;
    # 告诉编译器 numa全局的
    global numa
    numa = 50
    print("我是函数", numa)


fun()

print(numa)  # 100

count = 50
def outer():
    count = 10

    def inner():
        nonlocal count
        # global  count
        count = 20
        print(count)
    #
    inner()
    print(count) #  20

outer()
print(count)


# 函数的递归
# !n    3! = 3 * !2
# !n    3! = 3 * 2 * !1
# !n    3! = 3 * 2 * 1

def jiec(num):
    if num == 1:
        return 1
    return num * jiec(num-1)

print("2! = ",jiec(2));
print("3! = ",jiec(3));
print("4! = ",jiec(4));
#   2 * jiec(2-1)
#   2 * jiec(1)
#   2 * 1

#   3 * jiec(2)
#   3 * 2 * jiec(1)
#  3 * 2 * 1


